package com.ofek.applicationbase.forms.question;

import android.content.Context;
import android.view.View;

import com.ofek.applicationbase.R;
import com.ofek.applicationbase.broadcast.Delegate;
import com.ofek.applicationbase.forms.QuestionView;


public class ConditionalQuestionView extends CheckBoxQuestionView {
	private Boolean visibleState = true;
	public ConditionalQuestionView(final int resourceId,final Context context) {
		super(R.layout.form_question_conditional,resourceId,context);

	}
	public ConditionalQuestionView(final int resourceId,final Context context,final boolean visibleState) {
		this(resourceId,context);
		this.visibleState = visibleState;
	}
	public void addConditionalQuestion(final QuestionView actualQuestion) {
		actualQuestion.setVisibility((Boolean) getAnswer()==visibleState ? View.VISIBLE : View.GONE);
		registerAnswerChangedListener(new Delegate<Object>() {


			@Override
			public void invoke(final Object isChecked) {
				if ((Boolean)isChecked==visibleState) 
					actualQuestion.setVisibility(View.VISIBLE);
				else 
					actualQuestion.setVisibility(View.GONE);
			}
		});

	}

	@Override
	public void setAnswer(final Object defaultAnswer) {
		// TODO Auto-generated method stub
		super.setAnswer(defaultAnswer);
	}

}
